package com.example.demo.channel;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

/**
 * @PackageName: com.example.demo.channel
 * @ClassName: PubSubBean
 * @Description:
 * @Author: czl
 * @Date: 2025/7/27 15:09
 */
@Component
public class RedisMessagePublisher {

    private static final Logger log = LoggerFactory.getLogger(RedisMessagePublisher.class);
    @Autowired
    private StringRedisTemplate redisTemplate;

    public void publish(String channel, String message) {
        redisTemplate.convertAndSend(channel, message);
        log.info("发送消息至redis频道 [" + channel + "]: " + message);
    }
}
